package handler

import (
	"context"
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
	"time"
	"video_08_28/global"
	"video_08_28/internal/params"
)

func SendSms(c *gin.Context) {
	var req params.SendSmsForm

	if err := c.ShouldBindJSON(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    100000,
			"message": "验证失败",
			"data":    "",
		})
		return
	}

	code := rand.Intn(9000) + 1000

	global.RDB.Set(context.Background(), "sendSms"+req.Mobile+req.Stouter, code, time.Minute*5)

	//pkg.SendSms(req.Mobile, code)

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "短信发送成功",
		"data":    "",
	})
}
